//
//  ViewController.m
//  Test2
//
//  Created by 王冲 on 2019/1/30.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 100)];
    label.backgroundColor = [UIColor brownColor];
    label.text = @"我是Test2";
    label.font = [UIFont systemFontOfSize:25.f];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMidX(label.frame)-50, CGRectGetMaxY(label.frame)+50, 100, 50)];
    [button2 setBackgroundColor:[UIColor brownColor]];
    [button2 setTitle:@"跳转" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
}


-(void)click2{
    
    NSLog(@"跳转到Test");
    
    NSURL *url = [NSURL URLWithString:@"test1://"];
    
    // 注意: 跳转之前, 可以使用 canOpenURL: 判断是否可以跳转
    
    if (![[UIApplication sharedApplication]canOpenURL:url]) {
        return;
    }
    
    if (@available(iOS 10.0, *)){
        
        [[UIApplication sharedApplication]openURL:url options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:^(BOOL success) {
            
            if (success) {
                NSLog(@"10以后可以跳转url");
            }else{
                NSLog(@"10以后不可以跳转url");
            }
        }];
    }else{
        
        BOOL success = [[UIApplication sharedApplication]openURL:url];
        
        if (success) {
            NSLog(@"10以前可以跳转url");
        }else{
            NSLog(@"10以前不可以跳转url");
        }
    }
}

@end
